package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @Description:
 * @Version: V1.0
 */
public class ClearImgJob {

    @Autowired
    private JedisPool JedisPool;

    public void clearImg(){
        System.out.println("定时清理垃圾图片");
        Set<String> sdiff = JedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (sdiff!=null){
            for (String s : sdiff) {
                QiniuUtils.deleteFileFromQiniu(s);
                JedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,s);
            }
        }
    }
}
